<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo  Q::ini('appini/app_title')." ". Q::ini('appini/version');?></title>
<link href="css/default.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="js/jquery-easyui/themes/default/easyui.css"/>
<link rel="stylesheet" type="text/css" href="js/jquery-easyui/themes/icon.css"/>
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery-easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="js/jquery-easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>

<script language="javascript">
$().ready(function(){
	tree = $('#tree').tree({
		checkbox: false,
		methord:'get',
		url: '<?=url('category/list',array('comobotree'=>true))?>',
		onBeforeExpand: function (node, param) {
			//alert(node.id);
			$('#tree').tree('options').url = "<?=url('category/list',array('comobotree'=>true))?>?pid=" + node.id; // change the url                       
			//param.myattr = 'test';    // or change request parameter
		},
		onClick: function (node) {
			clickTree(node.id);
		}
	});
});

function clickTree(nodeid) {
    $("#dg").datagrid({ url: '<?=url('product/list')?>', queryParams: { category_id: nodeid} });
    $("#dg").datagrid('clearSelections');
}

function newproduct(){  
    $('#dlg').dialog('open').dialog('setTitle','添加商品');  
    $('#fm').form('clear');  
    url = '<?=url("product/new")?>';  
} 

function editproduct(){
	var row = $('#dg').datagrid('getSelected');  
    if (row){  
        $('#dlg').dialog('open').dialog('setTitle','编辑商品');  
        $('#fm').form('load',row);  
		url = '<?=url("product/update")?>';
    } 
	else{
		$.messager.show({
			'title': "提示",
			'msg': "请选择要编辑的记录."	
		});	
	} 		
}

function saveproduct(){  

	$('#fm').form('submit',{  
		url: url,  
		onSubmit: function(){  
			return $(this).form('validate');  
		},  
		success: function(result){  
			var result = eval('('+result+')');  
			if (result.errorMsg){  
				$.messager.show({  
					title: '出错了',  
					msg: result.errorMsg  
				});  
			} else {  
				$('#dlg').dialog('close');      // close the dialog  
				$('#dg').datagrid('reload');    // reload the user data  
			}  
		}  
	});  
}  

function destroyproduct(){  
    var row = $('#dg').datagrid('getSelected');  
    if (row){  
        $.messager.confirm('确认','您确认要删除该记录吗?',function(r){  
            if (r){  
                $.post('<?=url("product/destroy")?>',{id:row.product_id},function(result){  
                    if (result.success){  
                        $('#dg').datagrid('reload');    // reload the user data  
                    } else {  
                        $.messager.show({   // show error message  
                            title: '出错了',  
                            msg: result.errorMsg  
                        });  
                    }  
                },'json');  
            }  
        });  
    }
	else{
		$.messager.show({   // show error message  
			title: '提示',  
			msg: "请选择要删除的记录."
		});  	
	}  
}

function searchproduct(){  
    $('#dlgSearch').dialog('open').dialog('setTitle','查找');  
}

function doSearch(){
	key=$("#key").val()
	op=$("#op").val();
	value=$("#value").val();
	$("#dg").datagrid({ url: '<?=url('product/list')?>', queryParams: { key: key,op:op,value:value} });
	
	$('#dlgSearch').dialog('close');
} 
</script>
</head>
<body class="easyui-layout" style="overflow-y: hidden" scroll="no">
    <div region="west" split="true" title="商品分类" style="width: 180px;" id="west">
        <ul id="tree">
        
        </ul>
    </div>
    <div region="center" style="width: 500px; height: 300px; padding: 1px;overflow-y: hidden">
        <table id="dg" title="商品管理"  class="easyui-datagrid" url="<?=url("product/list")?>"  toolbar="#toolbar"  rownumbers="true" fitColumns="true" singleSelect="true" iconCls="icon-save"  pagination="true" fit="true">  
        	<thead>  
                <tr>  
                    <th field="code" width="50">商品编码</th>  
                    <th field="name" width="50">商品名称</th>  
                    <th field="category_name" width="50">所属类别</th>
                    <th field="brand_name" width="50">商品品牌</th>
                    <th field="supplier_name" width="50">供应商</th>
                    <th field="chandi" width="50">产地</th>
                    <th field="guige" width="50">规格</th>
                    <th field="sale_price" width="50">销售价格</th>
                </tr>  
        	</thead>  
    	</table>  
    	<div id="toolbar">  
            <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newproduct()">新增</a> | 
            <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editproduct()">编辑</a> |  
            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyproduct()">删除</a> |  
            <a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="searchproduct()">查找</a>
    	</div>  
    </div>
    
    
    <div id="dlg" class="easyui-dialog" style="width:700px;height:400px;" closed="true" buttons="#dlg-buttons"  modal="true">  
    <form id="fm" method="post">  
        <div class="easyui-tabs" style="width:100%;height:330px;" fit="true"> 
        <div title="基本信息" style="padding:10px">
          <table width="100%" border="0" cellspacing="1" cellpadding="2">
            <tr>
              <td height="25">编&nbsp;&nbsp;&nbsp;&nbsp;码</td>
              <td height="25"><input name="code" type="text" id="code" size="20" class="easyui-validatebox" required="required" /></td>
              <td height="25">条&nbsp;&nbsp;&nbsp;&nbsp;码</td>
              <td height="25"><input name="barcode" type="text" id="barcode" size="20" /></td>
            </tr>
            <tr>
              <td height="25">拼音码</td>
              <td height="25"><input name="pinyin" type="text" id="pinyin" size="20" /></td>
              <td height="25">品&nbsp;&nbsp;&nbsp;&nbsp;牌</td>
              <td height="25"><select name="brand_id" id="brand_id" class="easyui-combogrid" data-options="  
            panelWidth:350,            
            idField:'brand_id',  
            textField:'name',  
            url:'<?=url("brand/list")?>',  
            columns:[[  
                {field:'code',title:'编码',width:60},  
                {field:'name',title:'名称',width:280}  
            ]]">
              </select></td>
            </tr>
            <tr>
              <td height="25">名&nbsp;&nbsp;&nbsp;&nbsp;称</td>
              <td height="25" colspan="3"><input name="name" type="text" id="name" size="30" class="easyui-validatebox" required="required" /></td>
            </tr>
            <tr>
              <td height="25">型&nbsp;&nbsp;&nbsp;&nbsp;号</td>
              <td height="25"><input name="xinghao" type="text" id="xinghao" size="20" /></td>
              <td height="25">类&nbsp;&nbsp;&nbsp;&nbsp;别</td>
              <td height="25"><select name="category_id" id="category_id" class="easyui-combotree" data-options="  
            panelWidth:350,            
            idField:'category_id',  
            textField:'name',  
            url:'<?=url("category/list",array('comobotree'=>true))?>',  
            columns:[[  
                {field:'code',title:'编码',width:60},  
                {field:'name',title:'类别名称',width:180}  
            ]]">
              </select></td>
            </tr>
            <tr>
              <td height="25">规&nbsp;&nbsp;&nbsp;&nbsp;格</td>
              <td height="25"><input name="guige" type="text" id="guige" size="20" /></td>
              <td height="25">单&nbsp;&nbsp;&nbsp;&nbsp;位</td>
              <td height="25"><select name="unit_id" id="unit_id" class="easyui-combogrid" data-options="  
            panelWidth:250,            
            idField:'unit_id',  
            textField:'name',  
            url:'<?=url("unit/list")?>',  
            columns:[[  
                {field:'code',title:'编码',width:60},  
                {field:'name',title:'名称',width:180}  
            ]]">
              </select></td>
            </tr>
            <tr>
              <td height="25">产&nbsp;&nbsp;&nbsp;&nbsp;地</td>
              <td height="25"><input name="chandi" type="text" id="chandi" size="20" /></td>
              <td height="25">供应商</td>
              <td height="25"><select name="supplier_id" id="supplier_id" class="easyui-combogrid" data-options="  
            panelWidth:250,            
            idField:'supplier_id',  
            textField:'name',  
            url:'<?=url("supplier/list")?>',  
            columns:[[  
                {field:'code',title:'编码',width:60},  
                {field:'name',title:'名称',width:180}  
            ]]" >
              </select></td>
            </tr>
            <tr>
              <td height="25">屈光度</td>
              <td height="25"><input name="quguangdu" type="text" id="quguangdu" size="10" /></td>
              <td height="25">散光度</td>
              <td height="25"><input name="sanguangdu" type="text" id="sanguangdu" size="10" /></td>
            </tr>
            <tr>
              <td height="25">进货价</td>
              <td height="25"><input name="jinhuo_price" type="text" id="jinhuo_price" size="10" /></td>
              <td height="25">零售价</td>
              <td height="25"><input name="sale_price" type="text" id="sale_price" size="10" /></td>
            </tr>
            <tr>
              <td height="25">会员价</td>
              <td height="25"><input name="member_price" type="text" id="member_price" size="10" /></td>
              <td height="25"> 批发价</td>
              <td height="25"><input name="pifa_price" type="text" id="pifa_price" size="10" /></td>
            </tr>
            <tr>
              <td height="25">折扣价</td>
              <td height="25"><input name="zhekou_price" type="text" id="zhekou_price" size="10" /></td>
              <td height="25">&nbsp;</td>
              <td height="25">&nbsp;</td>
            </tr>
          </table>
        </div>
        <div title="辅助信息" style="padding:10px">
          <table width="100%" border="0" cellspacing="1" cellpadding="2">
            <tr>
              <td height="25">期初库存</td>
              <td height="25"><input name="qichu_kucun" type="text" id="qichu_kucun" size="10" /></td>
              <td height="25">库存上限</td>
              <td height="25"><input name="kucun_shangxian" type="text" id="kucun_shangxian" size="10" /></td>
              <td height="25">库存下限</td>
              <td height="25"><input name="kucun_xiaxian" type="text" id="kucun_xiaxian" size="10" /></td>
            </tr>
            <tr>
              <td height="25">最后进货价格</td>
              <td height="25"><input name="last_price" type="text" id="last_price" size="10" /></td>
              <td height="25">最后进货日期</td>
              <td height="25"><input name="last_stock" type="text" id="last_stock" size="10" /></td>
              <td height="25"><input name="product_id" type="hidden" id="product_id" /></td>
              <td height="25">&nbsp;</td>
            </tr>
             
          </table>
        </div>
       
        </div> </form>  
    </div>  
    <div id="dlg-buttons">  
        <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveproduct()">保存</a>  
        <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>  
    </div>   
    
    <!--search box-->
    <div id="dlgSearch" class="easyui-dialog" style="width:400px;height:200px;padding:10px 20px" closed="true" buttons="#dlgSearch-buttons"  modal="true"> 
    <form method="post">
    <select name="key" id="key" class="easyui-validatebox" required="true" >
    <option value="code">客户编码</option>
    <option value="name">客户姓名</option>
    <option value="telephone">固定电话</option>
    <option value="mobile">移动电话</option>
    <option value="qq">QQ</option>
    <option value="sex">性别</option>
    </select>
    <select name="op" id="op" class="easyui-validatebox" required="true" >
    <option value="=">等于</option>
    <option value=">">大于</option>
    <option value="<">小于</option>
    <option value="like">包含</option>
    </select>
    <input name="value" id="value" type="text" class="easyui-validatebox" required="true" />
    </form>
    </div>
    <div id="dlgSearch-buttons">  
        <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="doSearch()">查找</a>  
        <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlgSearch').dialog('close')">取消</a>  
    </div>  
      
</body>
</html>
